<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <title>账号安全</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/css/iconfont/iconfont.css" rel="stylesheet"/>
    <link href="/css/common.css" rel="stylesheet"/>
    <link href="/css/uc.css" rel="stylesheet"/>
    <link href="/layui/css/layui.css" rel="stylesheet">
</head>
<body>
<!--头部-->
<th:block th:include="header"/>
<div class="uc-header-bg">
    <div class="uc-header wrapper">
        <a class="logo" href="../index.html"><img src="/img/logo2.png" alt=""/></a>
        <div class="back-home"><a th:href="@{/static}">返回商城首页</a></div>
        <ul class="uc-nav">
            <li><a th:href="@{/}">首页</a></li>
        </ul>
    </div>
</div>

<div class="wrapper uc-router">
    <ul>
        <li><a href="">首页</a></li>
        <li><span class="divider"></span></li>
        <li><span>个人中心</span></li>
    </ul>
</div>

<div class="wrapper">
    <div class="uc-main clearfix">
        <div class="uc-aside">
            <div class="uc-menu">
                <div class="tit">订单中心</div>
                <ul class="sublist">
                    <li><a th:href="@{/user/order/ucOrder}">我的订单</a></li>
                </ul>
                <div class="tit">账户中心</div>
                <ul class="sublist">
                    <li><a th:href="@{/user/address}">收货地址</a></li>
                    <li><a th:href="@{/user/verify}">修改密码</a></li>
                </ul>
            </div>
        </div>
        <div class="uc-content">
            <div class="uc-panel">
                <div class="uc-bigtit bd-b">账号安全</div>
                <div class="uc-panel-bd">
                    <div class="verify-panel mt10">
                        <form id="rePwd">
                            <div class="inner-box">
                                <div class="control-group mt30">
                                    <div class="hd">旧密码：</div>
                                    <div class="bd">
                                        <input style="width: 220px;" class="ui-txtin" type="password" name="oldPwd"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="hd">新登录密码：</div>
                                    <div class="bd">
                                        <input style="width: 220px;" class="ui-txtin" type="password" name="newPwd"/>
                                    </div>
                                </div>
                                <div class="control-group mt30">
                                    <div class="hd">确认新密码：</div>
                                    <div class="bd">
                                        <input style="width: 220px;" class="ui-txtin" type="password" name="rePwd"/>
                                    </div>
                                </div>
                                <div class="submit-group mt30">
                                    <button class="layui-btn layui-bg-red " lay-submit lay-filter="resetPwd">修&ensp;改</button>
                                </div>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<!--脚部-->
<div class="fatfooter">

</div>
<!--脚部-->
</body>
<script src="js/jquery.js"></script>
<link rel="stylesheet" href="js/icheck/style.css"/>
<script src="js/icheck/icheck.min.js"></script>
<script src="js/laydate/laydate.js"></script>
<script src="js/global.js"></script>
<script src="/layui/layui.js"></script>
<script>
    //JS
    layui.use([ 'layer', 'form'], function () {
        var layer = layui.layer;
        var $ = layui.$;
        var form = layui.form;

        //表单的提交操作
        form.on('submit(resetPwd)', function (data) {
            //手动获取表单数据
            var oldPwd = $('[name="oldPwd"]').val();
            var newPwd = $('[name="newPwd"]').val();
            var rePwd = $('[name="rePwd"]').val();
            //ajax 发送修改密码的请求
            $.ajax({
                url: '/api/user/rePwd',//请求路径
                data: {oldPwd, newPwd, rePwd},//要传递参数
                type: 'post',//http的请求方式
                dataType: 'json',//返回数据类型
                success: function (result) {//成功的回调 result服务器返回的数据
                    if (result.code == 0) {
                        //成功
                        layer.msg("修改成功", {icon: 6}, function (index) {
                            //跳转到登录页面
                            window.location.href = '/';
                        });
                    } else {
                        //失败
                        layer.msg(result.msg, {icon: 5})
                    }
                },
                error: function () {
                    layer.msg('请求失败', {icon: 5});
                }
            });

            //阻止表单的自动提交
            return false;
        });
    });
</script>
</html>